from django.core.management.base import BaseCommand
from django.utils.text import slugify
from blog.models import Category, Tag


class Command(BaseCommand):
    help = '初始化标签和分类'

    def handle(self, *args, **options):
        categories = [
            'Python',
            'Django',
            'Linux',
            'Git',
            'JavaScript',
            'Vue',
            'React',
            'Node.js',
            'Webpack',
            'Bootstrap',
            'HTML',
            'CSS',
            'Java',

        ]
        for category in categories:
            # 查询Category中id最大值，插入时在该id+1
            Category.objects.get_or_create(name=category, slug=slugify(category),description='{}分类描述'.format(category))
            self.stdout.write(self.style.SUCCESS('创建分类：{}'.format(category)))
        tags = [
            'Python',
            'Django',
            'Linux',
            'Git',
            'JavaScript',
            'Vue',
            'React',
            'Node.js',
            'Webpack',
            'Bootstrap',
            'HTML',
            'CSS',
            'Java',

        ]
        for tag in tags:
            Tag.objects.get_or_create(name=tag, slug=slugify(tag))
            self.stdout.write(self.style.SUCCESS('创建标签：{}'.format(tag)))